﻿@model List<BusinessLayer.WorldArtPrice.Models.AdminUserExtend>
@{
    ViewBag.Title = "Admin User Managemen";
}

<h2>Admin User Management</h2>          
    <a class="bt_green" href="/Account/Create"><span class="bt_green_lft"></span><strong>Create</strong><span class="bt_green_r"></span></a>        
    <a class="bt_red" href="#" onclick="DeleteSelectedItems(this);"><span class="bt_red_lft"></span><strong>Delete items</strong><span class="bt_red_r"></span></a>    
    <p>
        @if (ViewData["ErrorMessage"] != null)
        {
            @Html.Label(ViewData["ErrorMessage"].ToString())
        }
    </p>
    <table id="rounded-corner">
        <thead>
            <tr>
                <th class="rounded-company" scope="col">
                    <input id="chkAll" onclick="javascript:SelectAll(this);" type="checkbox" />
                </th>
                <th class="rounded" scope="col">
                    User name
                </th>
                <th class="rounded" scope="col">
                    First name  
                </th>
                 <th class="rounded" scope="col">
                    Last name
                </th>
                <th class="rounded" scope="col">
                    Status
                </th>
                <th class="rounded" scope="col">
                    In Groups
                </th>
            
                <th class="rounded-q4" scope="col">
                </th>
            </tr>
            @foreach (var item in Model)
               { 
            <tr>
                <td>
                    @Html.CheckBox("check", new { itemid = item.UserID, refer = "chk", onclick = "javascript:SelectOne(this)" })
                </td>
                <td>
                    @item.UserName

                </td>
                <td>
                    @item.FirstName

                </td>
                 <td>
                    @item.LastName
                </td>
                <td>
                    @BackEnd.Common.Constants.Status.GetStringStatus(item.Status)
                </td>
                <td>
                    @if (!String.IsNullOrEmpty(item.Groups))
                    {
                        if (item.Groups.Length<30)
                        {
                            @item.Groups.TrimEnd(',')
                          }
                        else{
                            @item.Groups.TrimEnd(',').Substring(0,30) <span title="@item.Groups.TrimEnd(',')">...</span>
                        
                        }

                    }
               
                </td>
                <td>                    
                    <a href="/Account/Edit?id=@item.UserID"><img border="0" title="" alt="" src="/Content/Images/user_edit.png"></a>
                </td>
            </tr>
            } 
        </thead>
    </table>
    <input id="hidDs" type="hidden" />
    <script type="text/javascript">
        /*Check, Check All*/
        function SelectAll(spanChk) {

            var hidSelected = $("input[id='hidDs']");
            var chkList = $("input[refer='chk']");
            var str = "";

            for (var i = 0; i < chkList.length; i++) {
                var chk = chkList[i];
                chk.checked = spanChk.checked;
                if (chk.checked) {
                    str = str + $(chk).attr("itemid") + "_";
                }
            }
            str = str == "" ? "" : str.substring(0, str.length - 1);
            hidSelected.attr("value", str);
            //alert(hidSelected.val());
        }
        function SelectOne() {
            var hidSelected = $("input[id='hidDs']");
            var chkList = $("input[refer='chk']");
            var str = "";

            for (var i = 0; i < chkList.length; i++) {
                var chk = chkList[i];
                if (chk.checked) {
                    str = str + $(chk).attr("itemid") + "_";
                }
            }
            str = str == "" ? "" : str.substring(0, str.length - 1);
            hidSelected.attr("value", str);
        }
        function DeleteSelectedItems() {
            if (confirm('Are you sure that want delete these items?')) {
                var hidSelected = $("input[id='hidDs']");
                if (hidSelected.val() != "") {

                    var rows = $("input:checked");
                    rows.each(function () {
                        $(this).parent().parent().remove();
                    });
                    
                    var URL = '/Account/Delete/' + hidSelected.val();
                    $.post(URL, function (data) {
                        //                        alert(data);
                        //                        if (data == "1") {
                        //                            alert("Delete successful");
                        //                            
                        //                        }
                        //                        else {
                        //                            alert("Cannot delete selected items!");
                        //                        }
                    });

                }
            }
        }
    </script>
